<?php
/*!
* TalkBack basic-client registration page. 
* This file shows how to use the talkback library to implement the blog registration. 
* @Author: Elie Bursztein (elie _AT_ cs.stanford.edu)
* @version: 1.0
* @url: http://talkback.stanford.edu
* @Licence: LGPL
*/



require_once "config.php"; 				//configuration file
require_once "../library/talkback.php";	//the talkback cslient library 

//creating an instance of the lib
$tb = new TalkBack($dataDir, $debug);

//saving the random string
if (isset($_POST['randString']) ) {
	if(!$tb->saveRandString($_POST['randString'])) {
			die("there is an error storing the authority random string, make sure that the storing directory is writable\n");
	} else {
	?>
		Random string saved. <br>
		The next step is to go to <a href="https://talkback.stanford.edu">talkback.stanford.edu</a> and ask it to verify your blog and fetch your public key</a><br/>
		To make sure that everything is okay you can check your <a href="index.php">index page</a> headers to see that the random string and the link to the key are present.
	<?php
	}
//starting the registration process by generating the key
} else {
	
	//FIXME: test if the key already exists
	
	//generating key pair
	if (!$tb->keyGen()) {
		die("there is an error creating your public/priv key pairs, make sure that the storing directory is writable\n");
	} else {
?>

	Your keys have been succefully generated <br>

	The next step is to go to <a href="https://talkback.stanford.edu">talkback.stanford.edu</a> to register your blog </a><br/>
	Please enter in the box below the random string provided by the authority so it can verify your ownership and fetch your public key <br/>
	<form action="registration.php" method="post">
		<input type="text" name="randString"/>
		<input type="submit" name="submit"/>	
		</form>
	
<?php
	}
}
?>
